package org.Lin.service;

import org.Lin.dao.ChatRoomMessageDAO;
import org.Lin.model.ChatRoomMessage;
import org.Lin.util.LogUtil;

import java.sql.SQLException;
import java.time.LocalDateTime;

public class ChatRoomMessageService {

    private final ChatRoomMessageDAO chatRoomMessageDAO = new ChatRoomMessageDAO();

    public boolean sendMessage(int senderId, String message) {
        try {
            ChatRoomMessage msg = new ChatRoomMessage();
            msg.setSenderId(senderId);
            msg.setMessage(message);
            msg.setSentTime(LocalDateTime.now());
            msg.setMessageStatus("正常");
            chatRoomMessageDAO.insert(msg);

            LogUtil.logOperation("ChatRoomMessage", "send", "发送群聊消息: " + message);
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }
}
